<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <input type="text" id="input">
  <p>
    输入框的内容是：
    <span id="span"></span>
  </p>
  <script>
    var person = {name: 'jjj'};
    Object.defineProperty(person, 'name', {
      get() {
        console.log('访问person的name属性时触发');
      },
      set(val) {
        // console.log('修改person的name属性时触发');
        span.innerHTML = val
      }
    })
    input.onchange = function(e) {
      // console.log(e.target.value);
      person.name = e.target.value;
    }
  </script>
</body>
</html>